'use strict';

var app = angular.module('simpleApp',
    ['simpleApp.directives', 'simpleApp.services','ngRoute']);

app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/auth/login',{
        controller:'LoginCtrl',               //登录
        templateUrl:'views/LoginForm.html'
    }).when('/auth/register',{
            controller: 'RegisterCtrl',         //注册
            templateUrl:'views/RegisterForm.html'
    }).when('/work/arithmeticExercise/:username',{
            controller: 'ExerciseCtrl',         //显示某个学生的数据
            resolve: {
                request: ["Student","$q","$route", function(Student,$q,$route) {
                    console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Student.get({username: $route.current.params.username},
                      function(request) {
                          delay.resolve(request);
                          //console.log("获取成功 " + $route.current.params.username);
                          //console.log("获取成功 " + $route.current.params.username);
                    }, function() {
                          delay.reject('Unable to fetch request');
                          console.log("获取失败 " + $route.current.params.username);
                    });
                    return delay.promise;
                }]
            },
            templateUrl:'views/arithmeticExercise.html'
    }).when('/work/arithmeticExerciseCopy/:username',{
            controller: 'ExerciseCtrlCopy',         //显示某个学生的数据
            resolve: {
                request: ["Student","$q","$route", function(Student,$q,$route) {
                    console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Student.get({username: $route.current.params.username},
                        function(request) {
                            delay.resolve(request);
                            //console.log("获取成功 " + $route.current.params.username);
                            //console.log("获取成功 " + $route.current.params.username);
                        }, function() {
                            delay.reject('Unable to fetch request');
                            console.log("获取失败 " + $route.current.params.username);
                        });
                    return delay.promise;
                }]
            },
            templateUrl:'views/arithmeticExerciseCopy.html'
        }).when('/work/arithmeticExercise2Copy/:username',{
            controller: 'ExerciseCtrl2Copy',         //显示某个学生的数据
            resolve: {
                request: ["Student","$q","$route", function(Student,$q,$route) {
                    console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Student.get({username: $route.current.params.username},
                        function(request) {
                            delay.resolve(request);
                            //console.log("获取成功 " + $route.current.params.username);
                            //console.log("获取成功 " + $route.current.params.username);
                        }, function() {
                            delay.reject('Unable to fetch request');
                            console.log("获取失败 " + $route.current.params.username);
                        });
                    return delay.promise;
                }]
            },
            templateUrl:'views/arithmeticExercise2Copy.html'
        }).when('/work/arithmeticExercise2/:username',{
            controller: 'ExerciseCtrl2',         //显示某个学生的数据
            resolve: {
                request: ["Student","$q","$route", function(Student,$q,$route) {
                  //  console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Student.get({username: $route.current.params.username},
                        function(request) {
                            delay.resolve(request);
                            //console.log("获取成功 " + $route.current.params.username);
                            //console.log("获取成功 " + $route.current.params.username);
                        }, function() {
                            delay.reject('Unable to fetch request');
                            console.log("获取失败 " + $route.current.params.username);
                        });
                    return delay.promise;
                }]
            },
            templateUrl:'views/arithmeticExercise2.html'
        }).when('/work/studentInformation/:username',{
            controller: 'StudentInformationCtrl',         //显示某个学生的数据
            resolve: {
                request: ["Student","$q","$route", function(Student,$q,$route) {
                    //console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Student.get({username: $route.current.params.username},
                        function(request) {
                            delay.resolve(request);
                            //console.log("获取成功 " + $route.current.params.username);
                            //console.log("获取成功 " + $route.current.params.username);
                        }, function() {
                            delay.reject('Unable to fetch request');
                            console.log("获取失败 " + $route.current.params.username);
                        });
                    return delay.promise;
                }]
            },
            templateUrl:'views/studentInformation.html'
        }).when('/work/simpleStudentInformation/:username&:studentName',{
            controller: 'ParentStudentInformationCtrl',         //显示某个学生的数据
            resolve: {
                request: ["Student","$q","$route", function(Student,$q,$route) {
                   // console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Student.get({username: $route.current.params.studentName},
                        function(request) {
                            delay.resolve(request);
                            //console.log("获取成功 " + $route.current.params.username);
                            //console.log("获取成功 " + $route.current.params.username);
                        }, function() {
                            delay.reject('Unable to fetch request');
                            console.log("获取失败 " + $route.current.params.username);
                        });
                    return delay.promise;
                }]
            },
            templateUrl:'views/simpleStudentInformation.html'
        }).when('/work/parentInformation/:username',{
            controller: 'ParentInformationCtrl',         //显示某个学生的数据
            resolve: {
                request: ["Parent","$q","$route", function(Parent,$q,$route) {
                    console.log("路径参数 " + $route.current.params.username);
                    var delay = $q.defer();
                    Parent.get({username: $route.current.params.username},
                        function(request) {
                            delay.resolve(request);
                            //console.log("获取成功 " + $route.current.params.username);
                            //console.log("获取成功 " + $route.current.params.username);
                        }, function() {
                            delay.reject('Unable to fetch request');
                            console.log("获取失败 " + $route.current.params.username);
                        });
                    return delay.promise;
                }]
            },
            templateUrl:'views/parentInformation.html'
        }).when('/work/showParticipants',{             //显示登录员工的请假请求
            controller: 'ParticipantListCtrl',
            resolve: {
                request: ["Participant","$q", function(Participant,$q) {    //获得查询结果，赋予变量
                    var delay = $q.defer();
                    Participant.query(function(requests) {
                        delay.resolve(requests);
                    }, function() {
                        delay.reject('Unable to fetch requests');
                    });
                    return delay.promise;
                }]
            },
            templateUrl:'views/ParticipantList.html'
    }).when('/work/fillInInformation',{                //填写新的请假请求
            controller: 'LeaveRequestCtrl',
            templateUrl:'views/AskForLeave.html'
    }).when('/auth/test',{                //填写新的请假请求
            controller: 'TestCtrl',
            templateUrl:'views/Test.html'
    });
  }]);

var url = '/arithmetic/RESTfulServices/calculate';
//following are the controllers
app.controller('LoginCtrl', ['$scope', "$http",'$location','$window',
    function($scope,$http,$location,$window) {
    console.log($('#navbar'));
    $scope.login = function(){
        $http.post(url + '/login', [$scope.participant.username,$scope.participant.password]
        ).success(function(responseFromServer){
              $scope.response = responseFromServer;
              if($scope.response[0] == "failure"){
                  console.log("failed");
              }
              else{
                  console.log($scope.response[1]);
                  if($scope.response[1] == "student"){
                      $location.path("work/arithmeticExerciseCopy/" + $scope.participant.username);
                  }
                  else{
                      $location.path("work/parentInformation/" + $scope.participant.username);
                  }
              }
        });
    };
    $scope.register = function(){
        $location.path("/auth/register");
    };
}]);
app.controller('RegisterCtrl', ['$scope', "$http",'$location','$window',
    function($scope,$http,$location,$window) {
        $scope.participant = {};
        $scope.register = function(arg1){
            console.log($scope.participant.tempField);
            if($scope.participant.password === $scope.participant.tempField){
               $http.post(url + '/register', [$scope.participant,$scope.participant.registerType])
                    .success(function(responseFromServer){
                       if($scope.participant.registerType == "student"){
                           $location.path("work/arithmeticExercise/" + $scope.participant.username);
                       }
                       else{
                           $location.path("work/parentInformation/" + $scope.participant.username);
                       }
               });
            } else{
                alert("两次输入的密码不一致");
            }
        };
    }]);
app.controller('ExerciseCtrl', ['$scope', "$http",'$location','request','calculateService',"$route","$rootScope",function($scope,$http,$location,request,calculateService,$route,$rootScope) {
        $scope.student = request;
        $scope.username = request.username;
        $scope.exercises = [];

        Date.prototype.Format = function(fmt)
        { //author: meizz
            var o = {
                "M+" : this.getMonth()+1,                 //月份
                "d+" : this.getDate(),                    //日
                "h+" : this.getHours(),                   //小时
                "m+" : this.getMinutes(),                 //分
                "s+" : this.getSeconds(),                 //秒
                "q+" : Math.floor((this.getMonth()+3)/3), //季度
                "S"  : this.getMilliseconds()             //毫秒
            };
            if(/(y+)/.test(fmt))
                fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
            for(var k in o)
                if(new RegExp("("+ k +")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
            return fmt;
        };
                                             //  6000
    var time1 = new Date(new Date().getTime() + 1801000).Format("MM/dd/yyyy hh:mm:ss");
    //console.log(time1);
    var interval = 1;
    $('.countdown').downCount({
            date: time1,
            offset: +0
        }, function () {
            alert('时间用完了!请刷新页面重新做题');
            $("#btnSubmit").attr("disabled","disabled");
        });
    /*$rootScope.$on('$routeChangeSuccess', function() {
        clearInterval(interval);
        alert("test");
    });  */
        var amount = 10;
        for(var i = 0;i < amount;i++){
            $scope.exercises.push(calculateService.createEasy());
        }
        $scope.returnMainPage = function(){
             $location.path("work/studentInformation/" + $scope.student.username);
        };
        $scope.refresh = function(){
            $route.reload();
        };
        $scope.submitExerciseResult = function(){
            for(var i = 0;i < amount;i++){
                if($scope.exercises[i][3] != Number($scope.exercises[i][5])){
                    $scope.exercises[i][6] = "错误";
                }
                else{
                    $scope.exercises[i][6] = "正确";
                }
            }
            var exerciseResult = [[0,0],[0,0],[0,0],[0,0]];    //类型，题目数，正确数
            for(i = 0;i < amount;i++){
                exerciseResult[$scope.exercises[i][4]][0]++;
                if($scope.exercises[i][6] == "正确"){
                    exerciseResult[$scope.exercises[i][4]][1]++;
                }
            }
            $("#btnSubmit").attr("disabled","disabled");
            for(var m = 0; m < amount; m++){
                var temp = document.getElementById("exerciseResult" + m.toString());
                if($scope.exercises[m][6] == "正确"){
                    temp.innerHTML = "<span class='alert alert-success' role='alert'><span class='glyphicon glyphicon-check'></span><span>答案正确</span></span>";
                }
                else{
                    temp.innerHTML ="<span class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation-sign'></span><span>错误，答案：" + $scope.exercises[m][3].toString() + "</span></span>";
                }
            }
            //上传做题结果
            $http.post(url + '/exercise',[$scope.student.username,exerciseResult]
            ).success(function(responseFromServer){
               $scope.response = responseFromServer;
               //console.log("ahahaha  "  + responseFromServer);
            });

        };
    }]);
app.controller('ExerciseCtrlCopy', ['$scope', "$http",'$location','request','calculateService',"$route","$rootScope",function($scope,$http,$location,request,calculateService,$route,$rootScope) {
    $scope.student = request;
    $scope.username = request.username;
    $scope.exercises = [];

    var amount = 10;
    for(var i = 0;i < amount;i++){
        $scope.exercises.push(calculateService.createEasy());
    }
    $scope.refresh = function(){
        $route.reload();
    };
    $scope.submitExerciseResult = function(){
        for(var i = 0;i < amount;i++){
            if($scope.exercises[i][3] != Number($scope.exercises[i][5])){
                $scope.exercises[i][6] = "错误";
            }
            else{
                $scope.exercises[i][6] = "正确";
            }
        }
        var exerciseResult = [[0,0],[0,0],[0,0],[0,0]];    //类型，题目数，正确数
        for(i = 0;i < amount;i++){
            exerciseResult[$scope.exercises[i][4]][0]++;
            if($scope.exercises[i][6] == "正确"){
                exerciseResult[$scope.exercises[i][4]][1]++;
            }
        }
        $("#btnSubmit").attr("disabled","disabled");
        for(var m = 0; m < amount; m++){
            var temp = document.getElementById("exerciseResult" + m.toString());
            if($scope.exercises[m][6] == "正确"){
                temp.innerHTML = "<span class='alert alert-success' role='alert'><span class='glyphicon glyphicon-check'></span><span>答案正确</span></span>";
            }
            else{
                temp.innerHTML ="<span class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation-sign'></span><span>错误，答案：" + $scope.exercises[m][3].toString() + "</span></span>";
            }
        }
    };
}]);
app.controller('ExerciseCtrl2', ['$scope', "$http",'$location','request','calculateService','$route',function($scope,$http,$location,request,calculateService,$route) {
    $scope.student = request;
    $scope.username = request.username;
    $scope.exercises = [];

    Date.prototype.Format = function(fmt)
    { //author: meizz
        var o = {
            "M+" : this.getMonth()+1,                 //月份
            "d+" : this.getDate(),                    //日
            "h+" : this.getHours(),                   //小时
            "m+" : this.getMinutes(),                 //分
            "s+" : this.getSeconds(),                 //秒
            "q+" : Math.floor((this.getMonth()+3)/3), //季度
            "S"  : this.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    };

  var time1 = new Date(new Date().getTime() + 1801000).Format("MM/dd/yyyy hh:mm:ss");
      $('.countdown').downCount({
        date: time1,
        offset: +0
    }, function () {
        alert('时间用完了!请刷新页面重新做题');
        $("#btnSubmit").attr("disabled","disabled");
    });


    var amount = 10;
    for(var i = 0;i < amount;i++){
        $scope.exercises.push(calculateService.createHard());
    }
    $scope.refresh = function(){
        $route.reload();
    };
    $scope.submitExerciseResult = function(){
        for(i = 0;i < amount;i++){
            if($scope.exercises[i][2] != Number($scope.exercises[i][1])){
                $scope.exercises[i][3] = "错误";
            }
            else{
                $scope.exercises[i][3] = "正确";
            }
        }
        var  exerciseResult = [0,0];
        for(i = 0;i < amount;i++){
            exerciseResult[0]++;
            if($scope.exercises[i][3] == "正确"){
                exerciseResult[1]++;
            }
        }
        //console.log(exerciseResult);
        $("#btnSubmit").attr("disabled","disabled");
        for(var m = 0; m < amount; m++){
            var temp = document.getElementById("exerciseResult" + m.toString());
            if($scope.exercises[m][3] == "正确"){
                temp.innerHTML = "<span class='alert alert-success' role='alert'><span class='glyphicon glyphicon-check'></span><span>答案正确</span></span>";
            }
            else{
                temp.innerHTML ="<span class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation-sign'></span><span>错误，答案：" + $scope.exercises[m][1].toString() + "</span></span>";
            }
        }
        //上传做题结果
        $http.post(url + '/exercise2',[$scope.student.username,exerciseResult]
        ).success(function(responseFromServer){
                $scope.response = responseFromServer;
                //console.log("ahahaha  "  + responseFromServer);
            });

    };
}]);
app.controller('ExerciseCtrl2Copy', ['$scope', "$http",'$location','request','calculateService','$route',function($scope,$http,$location,request,calculateService,$route) {
    $scope.student = request;
    $scope.username = request.username;
    $scope.exercises = [];

    var amount = 10;
    for(var i = 0;i < amount;i++){
        $scope.exercises.push(calculateService.createHard());
    }
    $scope.refresh = function(){
        $route.reload();
    };
    $scope.submitExerciseResult = function(){
        for(i = 0;i < amount;i++){
            if($scope.exercises[i][2] != Number($scope.exercises[i][1])){
                $scope.exercises[i][3] = "错误";
            }
            else{
                $scope.exercises[i][3] = "正确";
            }
        }
        var  exerciseResult = [0,0];
        for(i = 0;i < amount;i++){
            exerciseResult[0]++;
            if($scope.exercises[i][3] == "正确"){
                exerciseResult[1]++;
            }
        }
        //console.log(exerciseResult);
        $("#btnSubmit").attr("disabled","disabled");
        for(var m = 0; m < amount; m++){
            var temp = document.getElementById("exerciseResult" + m.toString());
            if($scope.exercises[m][3] == "正确"){
                temp.innerHTML = "<span class='alert alert-success' role='alert'><span class='glyphicon glyphicon-check'></span><span>答案正确</span></span>";
            }
            else{
                temp.innerHTML ="<span class='alert alert-danger' role='alert'><span class='glyphicon glyphicon-exclamation-sign'></span><span>错误，答案：" + $scope.exercises[m][1].toString() + "</span></span>";
            }
        }

    };
}]);

app.controller('ParentStudentInformationCtrl', ['$scope', "$http",'$location','request','calculateService',"$route",function($scope,$http,$location,request,calculateService,$route) {
    $scope.parentName = $route.current.params.username;
    $scope.student = request;
    console.log(request);
    $scope.username = request.username;
    var histories =  request.histories;
    histories.sort(function(a,b){return a.id> b.id?1:-1});
    var tempList = [];
    var dateList = []
    for(var i= histories.length - 6 ; i < histories.length; i++){
        tempList.push((histories[i].plus_correct + histories[i].minus_correct +histories[i].multiply_correct +histories[i].divide_correct +histories[i].hybrid_correct)/(histories[i].total).toFixed(2));
        dateList.push(histories[i].date);
    }
    var lineChartData = {
        labels : dateList,
        datasets : [
            {
                label: "My First dataset",
                fillColor : "rgba(48, 164, 255, 0.2)",
                strokeColor : "rgba(48, 164, 255, 1)",
                pointColor : "rgba(48, 164, 255, 1)",
                pointStrokeColor : "#fff",
                pointHighlightFill : "#fff",
                pointHighlightStroke : "rgba(48, 164, 255, 1)",
                data : tempList
            }
        ]};
    var chart1 = document.getElementById("line-chart").getContext("2d");
    window.myLine = new Chart(chart1).Line(lineChartData, {
        responsive: true
    });
    //easy pie chart
    $scope.easyPieChartData = [];
    var tmp1 = [0,0,0,0];
    var tmp2 = [0,0,0,0];
    for(i= 0 ; i < histories.length; i++){
        tmp1[0] +=  histories[i].plus;
        tmp1[1] +=  histories[i].minus;
        tmp1[2] +=  histories[i].multiply;
        tmp1[3] +=  histories[i].divide;
        tmp2[0] +=  histories[i].plus_correct;
        tmp2[1] +=  histories[i].minus_correct;
        tmp2[2] +=  histories[i].multiply_correct;
        tmp2[3] +=  histories[i].divide_correct;
    }
    for(i = 0; i < 4; i++){
        if(tmp1[i] != 0){
            $scope.easyPieChartData.push(Math.floor(tmp2[i]/tmp1[i].toFixed(2)*100.0));
        }
        else{
            $scope.easyPieChartData.push(0.00);
        }
    }

    $('#easypiechart-blue').attr("data-percent",$scope.easyPieChartData[0].toString());
    $('#easypiechart-blue').easyPieChart({
        scaleColor: false,
        barColor: '#30a5ff'
    });

    $('#easypiechart-orange').attr("data-percent",$scope.easyPieChartData[1].toString());
    $('#easypiechart-orange').easyPieChart({
        scaleColor: false,
        barColor: '#ffb53e'
    });
    $('#easypiechart-teal').attr("data-percent",$scope.easyPieChartData[2].toString());
    $('#easypiechart-teal').easyPieChart({
        scaleColor: false,
        barColor: '#1ebfae'
    });
    $('#easypiechart-red').attr("data-percent",$scope.easyPieChartData[3].toString());
    $('#easypiechart-red').easyPieChart({
        scaleColor: false,
        barColor: '#f9243f'
    });


    /*var color = ["#F7464A","#46BFBD","#FDB45C","#949FB1","#4D5360"];
     var highlight = ["FF5A5E","5AD3D1","FFC870","A8B3C5","616774"];
     var label = ["a","b","c","d","e","f","g","h","i"];
     var doughnutData = [];
     for(i=0; i < 6; i++){
     doughnutData.push({value:histories[i].id,
     color:color[i],
     highlight: highlight[i],
     label: label[i]});
     }*/
    /* var shape2 = document.getElementById("canvas2").getContext("2d");
     window.myDoughnut = new Chart(shape2).Doughnut(doughnutData, {responsive : true});*/
}]);

app.controller('StudentInformationCtrl', ['$scope', "$http",'$location','request','calculateService',function($scope,$http,$location,request,calculateService) {
        $scope.student = request;
        console.log(request);
        $scope.username = request.username;
        var histories =  request.histories;
        histories.sort(function(a,b){return a.id> b.id?1:-1});
        var tempList = [];
        var dateList = []
        for(var i= histories.length - 6 ; i < histories.length; i++){
            tempList.push((histories[i].plus_correct + histories[i].minus_correct +histories[i].multiply_correct +histories[i].divide_correct +histories[i].hybrid_correct)/(histories[i].total).toFixed(2));
            dateList.push(histories[i].date);
        }
        var lineChartData = {
            labels : dateList,
            datasets : [
                {
                    label: "My First dataset",
                    fillColor : "rgba(48, 164, 255, 0.2)",
                    strokeColor : "rgba(48, 164, 255, 1)",
                    pointColor : "rgba(48, 164, 255, 1)",
                    pointStrokeColor : "#fff",
                    pointHighlightFill : "#fff",
                    pointHighlightStroke : "rgba(48, 164, 255, 1)",
                    data : tempList
                 }
            ]};
            var chart1 = document.getElementById("line-chart").getContext("2d");
            window.myLine = new Chart(chart1).Line(lineChartData, {
                responsive: true
            });
            //easy pie chart
            $scope.easyPieChartData = [];
            var tmp1 = [0,0,0,0];
            var tmp2 = [0,0,0,0];
            for(i= 0 ; i < histories.length; i++){
                tmp1[0] +=  histories[i].plus;
                tmp1[1] +=  histories[i].minus;
                tmp1[2] +=  histories[i].multiply;
                tmp1[3] +=  histories[i].divide;
                tmp2[0] +=  histories[i].plus_correct;
                tmp2[1] +=  histories[i].minus_correct;
                tmp2[2] +=  histories[i].multiply_correct;
                tmp2[3] +=  histories[i].divide_correct;
            }
            for(i = 0; i < 4; i++){
                if(tmp1[i] != 0){
                    $scope.easyPieChartData.push(Math.floor(tmp2[i]/tmp1[i].toFixed(2)*100.0));
                }
                else{
                    $scope.easyPieChartData.push(0.00);
                }
            }

    $('#easypiechart-blue').attr("data-percent",$scope.easyPieChartData[0].toString());
            $('#easypiechart-blue').easyPieChart({
                scaleColor: false,
                barColor: '#30a5ff'
            });

            $('#easypiechart-orange').attr("data-percent",$scope.easyPieChartData[1].toString());
            $('#easypiechart-orange').easyPieChart({
                scaleColor: false,
                barColor: '#ffb53e'
            });
            $('#easypiechart-teal').attr("data-percent",$scope.easyPieChartData[2].toString());
            $('#easypiechart-teal').easyPieChart({
                scaleColor: false,
                barColor: '#1ebfae'
            });
            $('#easypiechart-red').attr("data-percent",$scope.easyPieChartData[3].toString());
            $('#easypiechart-red').easyPieChart({
                scaleColor: false,
                barColor: '#f9243f'
            });


            /*var color = ["#F7464A","#46BFBD","#FDB45C","#949FB1","#4D5360"];
            var highlight = ["FF5A5E","5AD3D1","FFC870","A8B3C5","616774"];
            var label = ["a","b","c","d","e","f","g","h","i"];
            var doughnutData = [];
            for(i=0; i < 6; i++){
                doughnutData.push({value:histories[i].id,
                    color:color[i],
                    highlight: highlight[i],
                    label: label[i]});
            }*/
           /* var shape2 = document.getElementById("canvas2").getContext("2d");
            window.myDoughnut = new Chart(shape2).Doughnut(doughnutData, {responsive : true});*/
    }]);
app.controller('ParentInformationCtrl', ['$scope', "$http",'$location','request','calculateService',function($scope,$http,$location,request,calculateService) {
    $scope.parent = request;
    console.log(request);
    $scope.username = request.username;
    $scope.children = request.students;
    $scope.childName = "";

    $scope.newChild = function(){
        $http.post(url + '/newChild', [$scope.username,$scope.childName]
        ).success(function(responseFromServer){
                if(responseFromServer[0] == "wrong child name"){
                    alert("孩子用户名错误");
                }
                else{
                    alert("绑定账号成功");
                }
            });
    }
}]);